package com.yugong.controller;

import com.github.pagehelper.PageInfo;
import com.yugong.common.Result;
import com.yugong.entity.vo.request.CollageRequestVO;
import com.yugong.entity.vo.response.CollageListResponseVO;
import com.yugong.service.CollageService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 学院控制器类
 *
 * @author yugong
 * @date 2024/2/25
 */
@RestController
@RequestMapping("/api/collage")
public class CollageController {
    @Resource
    private CollageService collageService;

    /**
     * 根据学院名查询学院
     *
     * @param pageNum     当前页
     * @param pageSize    当前页数据总数
     * @param collageName 学院名
     * @return 学院
     */
    @GetMapping("/find-collage-page")
    public Result findCollagePage(@RequestParam(defaultValue = "1") Integer pageNum,
                                  @RequestParam(defaultValue = "5") Integer pageSize,
                                  @RequestParam String collageName) {
        PageInfo<CollageListResponseVO> collageListResponseVOPageInfo = collageService.findCollage(pageNum, pageSize, collageName);
        return Result.success(collageListResponseVOPageInfo);
    }

    /**
     * 查询学院
     *
     * @return 学院
     */
    @GetMapping("/find-collage")
    public Result findCollage() {
        List<CollageListResponseVO> collageListResponseVOList = collageService.findCollage();
        return Result.success(collageListResponseVOList);
    }

    /**
     * 新增学院
     *
     * @param collageRequestVO 学院请求实体类
     * @return 响应码
     */
    @PostMapping("/add-collage")
    public Result addCollage(@RequestBody CollageRequestVO collageRequestVO) {
        int addFlag = collageService.addCollage(collageRequestVO);
        return Result.success(addFlag);
    }

    /**
     * 修改学院
     *
     * @param collageRequestVO 学院请求实体类
     * @return 响应码
     */
    @PutMapping("/update-collage")
    public Result updateCollage(@RequestBody CollageRequestVO collageRequestVO) {
        int updateFlag = collageService.updateCollage(collageRequestVO);
        return Result.success(updateFlag);
    }

    /**
     * 删除学院
     *
     * @param collageNo 学院号
     * @return 响应码
     */
    @DeleteMapping("/delete-collage/{collageNo}")
    public Result deleteCollage(@PathVariable String collageNo) {
        int deleteFlag = collageService.deleteCollage(collageNo);
        return Result.success(deleteFlag);
    }
}
